@extends('admin.main')

@section('content')
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="m-b">
        <a href="javascript:;" onclick="history.back()" class="btn btn-default"><i class="fa fa-arrow-left"></i> 返回列表</a>
    </div>
    <div class="ibox">
        <div class="ibox-title">
            <h5>编辑</h5>
        </div>
        <div class="ibox-content">
            <form id="formAdd" method="post" class="form-horizontal">
                <div class="form-group">
                    <label class="col-sm-2 control-label">名称</label>
                    <div class="col-sm-5">
                        <input type="text" name="name" value="{{$link->name}}" class="form-control" required="" autofocus />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">链接</label>
                    <div class="col-sm-10">
                        <input type="text" name="url" value="{{$link->url}}" class="form-control" required="" />
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">标签</label>
                    <div class="col-sm-10">
                        @foreach($tags as $row)
                            <div class="checkbox-inline i-checks"><label>
                            @if(in_array($row->id, $tag_ids->all()))
                                <input type="checkbox" name="tag_id[]" value="{{$row->id}}" checked="" />
                            @else
                                <input type="checkbox" name="tag_id[]" value="{{$row->id}}" />
                            @endif
                            {{$row->tag}}</label></div>
                        @endforeach
                    </div>
                </div>
                <div class="hr-line-dashed"></div>
                <div class="form-group">
                    <div class="col-sm-4 col-sm-offset-2">
                        <input type="hidden" name="id" value="{{$link->id}}" />
                        <button class="btn btn-primary btn-w-m" type="submit">提交</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
@endsection

@section('pageheader')
<link href="{{cdn1('assets/iCheck/custom.css')}}" rel="stylesheet">
@endsection

@section('pagescript')
<script src="{{cdn1('assets/iCheck/icheck.min.js')}}"></script>
<script>
    $("#side-menu li[rel='entrust']").addClass("active")
        .find("ul").addClass("in")
        .find("li[rel='link']").addClass("active");

    $('.i-checks').iCheck({
        checkboxClass: 'icheckbox_square-green',
        radioClass: 'iradio_square-green',
    });

    seajs.use('models/linkModel', function(linkModel) {
        $("#formAdd").on("submit", function(){
            linkModel.update($(this).serialize(), function(){
                window.location.href = document.referrer;
            }, failure);
            return false;
        });
    });
</script>
@endsection
